import { reqCategoryList, reqBannerList, reqFloorList } from '@/api'

const state = {
    categoryList: [],
    // 轮播图数据
    bannerList: [],
    floorList: []
}
const actions = {
    async categoryList ({ commit }) {
        let result = await reqCategoryList()
        // console.log(result);
        if (result.code == 200) {
            commit('CATEGORYLIST', result.data)
        }
    },
    // 获取首页轮播图数据
    async getBannerList ({ commit }) {
        let res = await reqBannerList()
        if (res.code == 200) {
            commit('GETBANNERLIST', res.data)
        }

    },
    // 获取floor数据
    async getFloorList ({ commit }) {
        let res = await reqFloorList()
        if (res.code == 200) {
            // 提交mutation
            commit('GETFLOORLIST', res.data)
        }

    }
}
const mutations = {
    CATEGORYLIST (state, categoryList) {
        state.categoryList = categoryList.splice(0, 16)
    },
    GETBANNERLIST (state, bannerList) {
        state.bannerList = bannerList
    },
    GETFLOORLIST (state, floorList) {
        state.floorList = floorList
    }

}
const getters = {}

export default {
    state,
    actions,
    mutations,
    getters
}